package com.gitee.magic.framework.base.context;

import com.gitee.magic.core.utils.StringUtils;

import jakarta.servlet.http.HttpServletRequest;

/**
 * @author start
 */
public class HttpHolder {

	public final static String REQUESTID="REQUESTID";
	public final static String REQUESTHTTP = "REQUESTHTTP";
	
	public static String getRequestId(HttpServletRequest request) {
		Object requestId=request.getAttribute(REQUESTID);
		if(requestId==null) {
			requestId=StringUtils.random();
			request.setAttribute(REQUESTID,requestId);
		}
		return String.valueOf(requestId);
	}
	
	public static Http getHttp(HttpServletRequest request) {
		Http http = (Http) request.getAttribute(REQUESTHTTP);
		if (http == null) {
			http = new Http(request);
			request.setAttribute(REQUESTHTTP, http);
		}
		return http;
	}
	
}
